package sismed.gui.comando;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sismed.negocio.fachada.Fachada;
import sismed.negocio.modelo.Pessoa;

public class ComandoGetMedico extends ComandoGenerico{
	@Override
	public void executar(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		if(request.getSession().getAttribute("tipoUsuario").equals(null))				
			response.sendRedirect("login.jsp");
		else{
			Fachada fachada = Fachada.getInstance();
			System.out.println(request.getSession().getAttribute("id").toString());
			Pessoa pessoa = fachada.recuperarPessoa(  request.getSession().getAttribute("id").toString() );
			
			request.setAttribute("Pessoa", pessoa);
			System.out.println(pessoa.getNome());
			request.setAttribute("teste", "ok");
			
			try 
			{			
				request.getRequestDispatcher("editarMedico.jsp").forward(request, response);
				
			} 
			catch (Exception e) 
			{
				e.printStackTrace();
				request.setAttribute("msgerro", e.getMessage());		
				
				request.getRequestDispatcher("erro.jsp").forward(request, response);	
			}
		}
		
	}	
}
